﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CorporationWars
{
    [Serializable]
    public class GameData
    {
        public List<string> corpStockNames = new List<string>();
        public Dictionary<string, Corporation> GlobalCorpListByID = new Dictionary<string, Corporation>();
        public List<Corporation> GlobalCorpList = new List<Corporation>();

        public Corporation playerCorp;

        public List<UIButton> HUDButtons = new List<UIButton>();

        public int Year = 2364;
        public int Cycle = 10;
        public CyberSector CurrentSector;

        public List<NewsItem> NewsFeed = new List<NewsItem>();
        public List<NewsItem> NewsArchive = new List<NewsItem>();

        public Dictionary<string, CyberSector> Sectors = new Dictionary<string, CyberSector>();

        public decimal StockCommisionPercentage = 10;

        public TimeSpan CycleStart = TimeSpan.Zero;
        public TimeSpan CycleSpan = new TimeSpan(0, 0, 5, 0, 0);
        public TimeSpan NextCycle { get { return CycleSpan - (DateTime.Now.TimeOfDay - CycleStart); } }
        public TimeSpan SavedTimeOfDay { get; set; }

        public TimeSpan lastRecordedSharePrice { get; set; }
        public TimeSpan nextRecorderSharePrice = new TimeSpan(0, 0, 0, 10, 0);
        public TimeSpan elapsedRecordTime { get { return nextRecorderSharePrice - (DateTime.Now.TimeOfDay - lastRecordedSharePrice); } }

        public List<decimal> CycleMarketValue = new List<decimal>();

        public void UnWire()
        {
            foreach (UIButton button in HUDButtons)
                button.OnClick = null;

            foreach (string key in Sectors.Keys)
                Sectors[key].UnWire();

            corpStockNames.Clear();
            GlobalCorpListByID.Clear();
            GlobalCorpList.Clear();
            playerCorp.UnWire();
            playerCorp = null;
            CurrentSector.UnWire();
            CurrentSector = null;
            NewsFeed.Clear();
            NewsArchive.Clear();
            Sectors.Clear();
            CycleMarketValue.Clear();
        }

        public void ReWire(Game1 game, UIEvent uiEvent)
        {
            // rewire all the buttons back up :S
            foreach (UIButton button in HUDButtons)
            {
                button.Game = game;
                button.OnClick = uiEvent;
            }

            foreach (string key in Sectors.Keys)
            {
                Sectors[key].Game = game;
                Sectors[key].ReWire(game);
            }
        }
    }
}
